<div class="SipeiMain_r fr">
    <h2 class="clearfix fonts_18 height45 fontc_444"><?php echo $this->title; ?></h2>	   
    <?php
    $form = $this->beginWidget('CActiveForm', array(
        'action' => Yii::app()->createUrl($this->route),
        'method' => 'GET',
        'id' => 'searchForm'
    )); ?>
    <ul class="clearfix back_bgf border_3 border_c pr30 pl20 pt20 pb20 height32 fontc_666">
        <li class="fl pt10 pr20 pb10 pl8">
            <span class="pr3">科目代码：</span><input type="text" name="subject_code" value="<?php echo $serch['subject_code']; ?>" class="pt6 pr5 pb6 pl5 border_3 border_c fontc_666 w100" />
        </li>
        <li class="fl pt10 pr30 pb10 pl3">
            <span class="pr3">科目名称：</span><input type="text" name="subject_name" value="<?php echo $serch['subject_name']; ?>" class="pt6 pr5 pb6 pl5 border_3 border_c fontc_666 w100" />
        </li>
        <!--
        <li class="fl pt10 pr30 pb10">
            <span class="fl pr8">是否生效</span><input type="checkbox" name="is_display"  class="fl mt9" />
        </li>
        -->
        <li class="fr pt10 pb10">
            <input type="submit" value="查询" class="b_a_n border_3 back_bgfb w80 height32 fontc_FFF fonts_12 cursor" />
        </li>
    </ul>
    <?php
    $this->endWidget(); ?>
    <div class="clearfix back_bgf border_c mt15 pt20 pb20">
        <div class="clearfix pb20 pl30">
            <input type="button" value="新增" onclick="add();" class="b_a_n border_3 back_bgfb w80 height32 fontc_FFF fonts_12 mr20 cursor fr" style="margin-right:30px;" />
            <input type="button" onclick="importExcel();" value="导出excel" class="fl b_a_n border_3 back_bgfb w80 height32 fontc_FFF fonts_12 cursor" />
            <input type="button" value="删除" onclick="delete_all();" class="fl b_a_n border_3 back_bgfb w80 height32 fontc_FFF fonts_12 ml20 cursor" />
        </div>
        <form>
            <table class="height40">
                <thead class="back_bgf5 fontc_666">
                    <tr>
                    	<th width="40" align="right" class="m_hr_t m_hr_b pr10"><input type="checkbox" class="checkboxs"></th>
                        <th width="150" align="center" class="m_hr_t m_hr_b">科目代码</th>
                        <th width="150" align="center" class="m_hr_t m_hr_b">科目名称</th>
                        <th width="65" align="center" class="m_hr_t m_hr_b">是否生效</th>
                        <th width="260" align="left" class="m_hr_t m_hr_b pl20">备注</th>
                        <th width="125" align="center" class="m_hr_t m_hr_b">操作</th>
                    </tr>
                </thead>
                <tbody class="fontc_444">
                    <?php if (!empty($data)): ?>
                        <?php foreach ($data as $value): ?>
                            <tr>
                            	<td align="right" class="m_hr_b pr10">
                            	<input type="checkbox" class="fr checkboxs" name="deleteAll[]" value="<?php echo $value['subject_id'];?>">
                            	</td>
                                <td align="center" class="m_hr_b height20 pt5 pb5"><?php echo $value['subject_code']; ?></td>
                                <td align="center" class="m_hr_b height20 pt5 pb5"><?php echo $value['subject_name']; ?></td>
                                <?php if ($value['disabled'] == 1): ?>
                                    <td align="center" class="m_hr_b">
                                        <input type="checkbox" disabled='' checked="checked" />
                                    </td>
                                <?php else: ?>
                                    <td align="center" class="m_hr_b"><input type="checkbox" disabled='' /></td>
                                <?php endif; ?>
                                <td align="left" class="m_hr_b pl20">
                                	<p style="line-height:1.5; padding:10px 0;"><?php echo $value['description']; ?></p>
                                </td>
                                <td align="center" class="m_hr_b">
                                    <a href="<?php echo $this->createUrl('/subject/default/question_list',array('subject_id'=>$value['subject_id']))?>" title="添加题型">
                                    <img src="/themes/default/images/Sipei/plus.png"  class="mr10 cursor" >
                                    </a>
                                    <img src="/themes/default/images/Sipei/edit.png" title="编辑" class="mr10 cursor" onclick="update(<?php echo $value['subject_id']; ?>)" />
                                    <img src="/themes/default/images/Sipei/delate.png" title="删除" class="cursor" onclick="set_ok(<?php echo $value['subject_id']; ?>)" />
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    <?php else: ?>
                        <tr>
                            <td colspan="6"><h1 align="center">暂无数据</h1></td>
                        </tr>
                    <?php endif; ?>			 
                </tbody>
            </table>
        </form>
        <?php $this->renderPartial('//partial/partial_pager', array('pages' => $pages, "listPage" => 10, "url" => $pageUrl)); ?>
    </div>
</div>

<script>
    function set_ok(subject_id) {
        $.dialog.confirm('确定删除吗', function() {
	       	 $.get('/subject/default/delete_all', {subject_id: subject_id}, function(data) {
		       	 if(data == 1){
			       	 location.reload();
			     }else if(data == 3){
					 $.dialog.alert("请清空题型数据后再进行删除操作");
					 return false;
				 }else{
					 $.dialog.alert("删除失败");
					 return false;
				}
	         });
        });
    }

    function add() {
        api = $.dialog({
            id: 'testID2',
            lock: true,
            padding: 0,
            fixed: true,
            title: "新增",
            width: 480,
            height: 360,
            max: false,
            min: false
        });
        $.get('/subject/default/add', function(html) {
            api.content(html);
        });
    }

    function delete_all(){
        var aa='';
        $("input[name='deleteAll[]']:checkbox:checked").each(function(){
            aa+=$(this).val()+',';
        });
        if(aa == ''){
            $.dialog.alert("请选择要删除条目");
            return false;
        }

        $.dialog.confirm('确定删除所选数据吗', function() {
            aa+=0;
            $.get('/subject/default/delete_all', {subject_id: aa}, function(data) {
	           	 if(data == 1){
			       	 location.reload();
			     }else if(data == 3){
					 $.dialog.alert("请清空题型数据后再进行删除操作");
					 return false;
				 }else{
					 $.dialog.alert("删除失败");
					 return false;
				}
            });
        });
    }
    
    /**
     *  导出信息
     *  jinyue.wang
     *  2013-01-16 
     * */
    function importExcel() {
    
        var subject_code = '<?php echo (!empty($search['subject_code'])) ? $search['subject_code'] : ''; ?>';
        var subject_name = '<?php echo (!empty($search['subject_name'])) ? $search['subject_name'] : ''; ?>';
        
        $.get('/subject/default/importexcel', {subject_code: subject_code,subject_name: subject_name}, function(data) {
            if(data==1){
                $.dialog.alert('导出数据不存在');
            }else{
                window.location.href = '<?php echo $this->createUrl('/subject/default/importexcel'); ?>/subject_code/'+subject_code+'/subject_name/'+subject_name;
            }
            return false;
        });
    }
                
    function update(subject_id) {

        api = $.dialog({
            id: 'testID2',
            lock: true,
            padding: 0,
            fixed: true,
            title: "编辑",
            width: 480,
            height: 360,
            max: false,
            min: false
        });
        $.get('/subject/default/update', {subject_id: subject_id,time:new Date()}, function(html) {
            api.content(html);
        });
    }
           
    $(function() {
        $(".checkboxs").click(function() {
            var checkedS = $(this).attr("checked");
            if (checkedS) {
                $(".checkbox").attr("checked", true)
            } else {
                $(".checkbox").removeAttr("checked")
            }
        });
    });
    function addQuestion(id) {
        window.location.href = "/subject/default/question_list/subject_id/" + id;
        return true;
    }
</script>